import axios from '@/libs/api.request';

export const login = ({ username, password }) => {
  const data = {
    username,
    password
  };
  return axios.request({
    url: 'login',
    method: 'POST',
    data: data
  });
};

export const getUserInfo = () => {
  return axios.request({
    // url: '/rest/user',
    url: '/userinfo',
    method: 'post'
  });
};

export const logout = (token) => {
  return axios.request({
    url: '/logout',
    method: 'post'
  });
};

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  });
};

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  });
};

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  });
};

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  });
};

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  });
};

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  });
};

export const userMenu = () => {
  return axios.request({
    // url: '/rest/menus',
    url: '/user/menus',
    method: 'post'

  });
};

// 修改密码
export const changePassword = (data) => {
  return axios.request({
    url: '/department/changePassword',
    method: 'POST',
    data: data
  });
};
